﻿namespace Vcare.Helpers
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using Vcare.Models;
  using System.Web.Mvc;
  using System.Configuration;
  using Vcare.DAL;

  public class AppLists
  {


    public List<PaymentTypes> ListPaymentType { get; set; }

    public List<SelectListItem> PricePlan { get; set; }

    public List<SelectListItem> Options { get; set; }

    public List<string> PaymentOption { get; set; }

    public List<SelectListItem> CardType { get; set; }

    private VcareContext db = new VcareContext();

    public void PopulateLists(int callCentreID=0)
    {
      this.ListPaymentType = new List<PaymentTypes>();
      ListPaymentType.Add(new PaymentTypes { PaymentType = "Debit Card" });
      ListPaymentType.Add(new PaymentTypes { PaymentType = "Direct Debit" });
      this.PricePlan = new List<SelectListItem>();
        // Annual fees 
        if (db.Rates.Any(m => m.CallCentreID==callCentreID && m.Annual == true))
	      {
          foreach (Rates rate in db.Rates.Where(m => m.Annual == true))
          {
            this.PricePlan.Add(new SelectListItem
            {
              Text = string.Format("{0} - £{1:.##}",rate.Description, rate.Fee),
              Value = string.Format("{0:.##}",  rate.Fee)
            });
          }
	      }
        else
	      {
          this.PricePlan.Add(new SelectListItem
          {
            Text = "Gold £" + ConfigurationManager.AppSettings["Gold Price Plan"] + " annual",
            Value = ConfigurationManager.AppSettings["Gold Price Plan"]
          });
	      }
        // Quarterly Fees
        if (db.Rates.Any(m => m.CallCentreID==callCentreID && m.Quarterly == true))
	      {
          foreach (Rates rate in db.Rates.Where(m => m.Quarterly == true))
          {
            this.PricePlan.Add(new SelectListItem
            {
              Text = string.Format("{0} - £{1:.##}",rate.Description, rate.Fee),
              Value = string.Format("{0:.##}",  rate.Fee)
            });
          }
	      }
        else
	      {
          this.PricePlan.Add(new SelectListItem
          {
            Text = "Silver £" + ConfigurationManager.AppSettings["Silver Price Plan"] + " per quarter",
            Value = ConfigurationManager.AppSettings["Silver Price Plan"]
          });
	      }
        // Monthly Fees
        if (db.Rates.Any(m => m.CallCentreID==callCentreID && m.Monthly == true))
	      {
          foreach (Rates rate in db.Rates.Where(m => m.Monthly == true))
          {
            this.PricePlan.Add(new SelectListItem
            {
              Text = string.Format("{0} - £{1:.##}",rate.Description, rate.Fee),
              Value = string.Format("{0:.##}",  rate.Fee)
            });
          }
	      }
        else
	      {
          this.PricePlan.Add(new SelectListItem
          {
            Text = "Bronze £" + ConfigurationManager.AppSettings["Bronze Price Plan"] + " per month",
            Value = ConfigurationManager.AppSettings["Bronze Price Plan"]
          });
        }
        
      this.CardType = new List<SelectListItem>();
      this.CardType.Add(new SelectListItem
      {
        Text = "MasterCard",
        Value = "MasterCard"
      });
      this.CardType.Add(new SelectListItem
      {
        Text = "VISA",
        Value = "VISA"
      });
      this.CardType.Add(new SelectListItem
      {
        Text = "Diners Club",
        Value = "Diners Club"
      });
      this.CardType.Add(new SelectListItem
      {
        Text = "American Express",
        Value = "American Express"
      });
      this.CardType.Add(new SelectListItem
      {
        Text = "Eurocard",
        Value = "Eurocard"
      });


      this.PaymentOption = new List<string>();
      this.PaymentOption.Add("Yearly - 1m free");
      this.PaymentOption.Add("Monthly");
      this.PaymentOption.Add("Quarterly 5% off");
    }
  }
}